//
//  EaseStartView.m
//  DLTravels
//
//  Created by mac1012 on 2016/12/15.
//  Copyright © 2016年 DianlE. All rights reserved.
//

#import "EaseStartView.h"
#import "StarImageManager.h"

@implementation EaseStartView

+ (instancetype)startEaseView{
    
    StarImage *startImage = [[StarImageManager shareStartImageManager] randomImage];
    return [[self alloc] initEaseStartViewBackGroundImage:startImage.image];
}

- (instancetype)initEaseStartViewBackGroundImage:(UIImage *)backImage{

    self = [super initWithFrame:kScreen_Bounds];
    if (self) {
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:kScreen_Bounds];
        
        bgImageView.image = backImage;
        bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        bgImageView.alpha = 0.0;
        self.bgImageView = bgImageView;
        [self addSubview:bgImageView];
        [self needsUpdateConstraints];
    }
    
    return self;
}


- (void)startAnimationWithCompletionBlock:(void(^)(EaseStartView *easeStartView))completionHandler{

    [kKeyWindow addSubview:self];
    [kKeyWindow bringSubviewToFront:self];
    //self.bgImageView.alpha = 0.0;
    @weakify(self);
    [UIView animateWithDuration:2.0 animations:^{
        @strongify(self);
        self.bgImageView.alpha = 1.0;
//        self.descriptionStrLabel.alpha = 1.0;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.6 delay:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
            @strongify(self);
            [self setX:-kScreen_Width];
        } completion:^(BOOL finished) {
            @strongify(self);
            [self removeFromSuperview];
            if (completionHandler) {
                completionHandler(self);
            }
        }];
    }];
}




@end
